<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class StoreSeckill extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     *允许批量赋值的字段
     */
    public $fillable = [
        'product_id',
        'recommend_image',
        'rotation_chart',
        'title',
        'introduction',
        'unit_name',
        'quota',
        'cost',
        'original_price',
        'quota_show',
        'once_num',
        'description',
        'temp_id',
        'price',
        'start_time',
        'stop_time',
        'time_id',
        'atr_status',
        'postage',
        'sort',
        'atr_status',
    ];

    /**
     * 强制转json
     */
    protected $casts = ['rotation_chart' => 'json'];

    /**
     * 可搜索的字段
     */
    public $searchable = [
        'id',
        'title',
        'status',
        'atr_status'
    ];

    /**
     * 设置模糊搜索
     */
    public $searchableModels = [
        'title' => '%field%',
    ];

    /**
     *可排序字段
     */
    public $sortable = [
        'created_at',
        'id',
        'is_show',
        'sales',
        'is_hot',
        'price',
    ];

    /**
     * 设置枚举值
     */
    public  $statusEnum = [
        'haveInHand' => '进行中',
        'completed' => '已结束',
        'noCompleted' => '未开始',
    ];

    /**
     * 默认倒序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 关联商品模型
     */

    public function product()
    {
        return $this->hasOne(Product::class, 'id', 'product_id');
    }

    /**
     * 关联单规格的模型
     */

    public function attrResult()
    {
        return $this->belongsTo(ProductAttrResult::class,'product_id','product_id');
    }


}
